@extends('admin.main')
@section('body')
    <div class="main-title">
        <h2>@if(isset($res['data']))[ {{$res['data']['title']}} ] @endif 记录管理 </h2>
    </div>

    <div class="cf">
        <a class="btn" href="{{urlAdmin('menu','getAdd',['pid'=>request('pid',0)])}}">新 增</a>
        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div class="sleft">
                <input type="text" name="title" class="search-input" value="{{request('title')}}" placeholder="请输入菜单名称">
                <a class="sch-btn" href="javascript:;" id="search" url="__SELF__"><i class="btn-search"></i></a>
            </div>
        </div>
    </div>

    <div class="data-table table-striped">
        <form class="ids">
            <table>
                <thead>
                    <tr>
                        <th class="row-selected">
                            <input class="checkbox check-all" type="checkbox">
                        </th>
                        <th>ID</th>
                        <th>名称</th>
                        <th>上级菜单</th>
                        <th>分组</th>
                        <th>URL</th>
                        <th>排序</th>
                        {{--<th>仅开发者模式显示</th>--}}
                        <th>隐藏</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                @if(count($res['list']))
                    @foreach($res['list'] as $v)
                    <tr>
                        <td><input class="ids row-selected" type="checkbox" name="id[]" value="{{$v['id']}}"></td>
                        <td>{{$v['id']}}</td>
                        <td>
                            <a href="{{urlAdmin('menu','getIndex',['pid'=>$v['id']])}}">{{$v['title']}}</a>
                        </td>
                        <td>{{$v['up_title'] or ''}}</td>
                        <td>{{$v['group']}}</td>
                        <td>{{$v['url']}}</td>
                        <td>{{$v['sort']}}</td>
                        {{--<td>--}}
                            {{--<a href="{{urlAdmin('menu','getToogleHide',['id'=>$v['id'],'value'=>abs($v['is_dev']-1)])}}" class="ajax-get">--}}
                            {{--{{$v['is_dev_text']}}--}}
                            {{--</a>--}}
                        {{--</td>--}}
                        <td>
                            <a href="{{urlAdmin('menu','getToogleHide',['id'=>$v['id'],'value'=>abs($v['hide']-1)])}}" class="ajax-get">
                            {{$v['hide_text']}}
                            </a>
                        </td>
                        <td>
                            <a title="编辑" href="{{urlAdmin('menu','getEdit',['id'=>$v['id']])}}">编辑</a>
                            <a class="confirm ajax-get" title="删除" href="{{urlAdmin('menu','anyDel',['id'=>$v['id']])}}">删除</a>
                        </td>
                    </tr>
                    @endforeach
                @else
                    <td colspan="9" class="text-center">aOh! 暂时还没有内容!</td>
                @endif
                </tbody>
            </table>
        </form>
        <!-- 分页 -->
        <div class="page">

        </div>
    </div>
@endsection
@section('script')
    <script type="text/javascript">
        $(function() {
            //搜索功能
            $("#search").click(function() {
                var url = $(this).attr('url');
                var query = $('.search-form').find('input').serialize();
                query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
                query = query.replace(/^&/g, '');
                if (url.indexOf('?') > 0) {
                    url += '&' + query;
                } else {
                    url += '?' + query;
                }
                window.location.href = url;
            });
            //回车搜索
            $(".search-input").keyup(function(e) {
                if (e.keyCode === 13) {
                    $("#search").click();
                    return false;
                }
            });
            //点击排序
        	$('.list_sort').click(function(){
        		var url = $(this).attr('url');
        		var ids = $('.ids:checked');
        		var param = '';
        		if(ids.length > 0){
        			var str = new Array();
        			ids.each(function(){
        				str.push($(this).val());
        			});
        			param = str.join(',');
        		}

        		if(url != undefined && url != ''){
        			window.location.href = url + '&ids=' + param;
        		}
        	});
        });
    </script>
@endsection